﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace MeizuSDK.Presentation
{
    /// <summary>
    /// 消息对话框
    /// </summary>
    public static class MessageBox
    {
        #region DllImport
        [DllImport("MZFCWrapper.dll")]
        private static extern int CommonDlgMessageBoxEx(IntPtr hWnd, string content, string title, int nType, int nHomeKeyReturnValue);
        #endregion

        #region 函数
        /// <summary>
        /// 显示消息对话框
        /// </summary>
        /// <param name="message">要显示的消息</param>
        /// <returns>返回结果，参见DialogResult类型</returns>
        public static DialogResult Show(string message)
        {
            return Show(message, string.Empty);
        }
        /// <summary>
        /// 显示消息对话框
        /// </summary>
        /// <param name="parent">打开此对话框的窗口</param>
        /// <param name="message">要显示的消息</param>
        /// <returns>返回结果，参见DialogResult类型</returns>
        public static DialogResult Show(IMzWindow parent, string message)
        {
            return Show(parent, message, string.Empty);
        }
        /// <summary>
        /// 显示消息对话框
        /// </summary>
        /// <param name="message">要显示的消息</param>
        /// <param name="title">对话框标题</param>
        /// <returns>返回结果，参见DialogResult类型</returns>
        public static DialogResult Show(string message, string title)
        {
            return Show(message, title, MessageBoxButtons.MZ_OK);
        }
        /// <summary>
        /// 显示消息对话框
        /// </summary>
        /// <param name="parent">打开此对话框的窗口</param>
        /// <param name="message">要显示的消息</param>
        /// <param name="title">对话框标题</param>
        /// <returns>返回结果，参见DialogResult类型</returns>
        public static DialogResult Show(IMzWindow parent, string message, string title)
        {
            return Show(parent, message, title, MessageBoxButtons.MZ_OK);
        }
        /// <summary>
        /// 显示消息对话框
        /// </summary>
        /// <param name="message">要显示的消息</param>
        /// <param name="title">对话框标题</param>
        /// <param name="buttons">要显示的按钮类型，参见MessageBoxButtons类型</param>
        /// <returns>返回结果，参见DialogResult类型</returns>
        public static DialogResult Show(string message, string title, MessageBoxButtons buttons)
        {
            return Show(message, title, buttons, HomeKeyReturnValue.SHK_RET_DEFAULT);
        }
        /// <summary>
        /// 显示消息对话框
        /// </summary>
        /// <param name="parent">打开此对话框的窗口</param>
        /// <param name="message">要显示的消息</param>
        /// <param name="title">对话框标题</param>
        /// <param name="buttons">要显示的按钮类型，参见MessageBoxButtons类型</param>
        /// <returns>返回结果，参见DialogResult类型</returns>
        public static DialogResult Show(IMzWindow parent, string message, string title, MessageBoxButtons buttons)
        {
            return Show(parent, message, title, buttons, HomeKeyReturnValue.SHK_RET_DEFAULT);
        }
        /// <summary>
        /// 显示消息对话框
        /// </summary>
        /// <param name="message">要显示的消息</param>
        /// <param name="title">对话框标题</param>
        /// <param name="buttons">要显示的按钮类型，参见MessageBoxButtons类型</param>
        /// <param name="homeKeyReturnValue">按home键后的默认返回值，参见HomeKeyReturnValue</param>
        /// <returns>返回结果，参见DialogResult类型</returns>
        public static DialogResult Show(string message, string title, MessageBoxButtons buttons, HomeKeyReturnValue homeKeyReturnValue)
        {
            return Show(null, message, title, buttons, homeKeyReturnValue);
        }
        /// <summary>
        /// 显示消息对话框
        /// </summary>
        /// <param name="parent">打开此对话框的窗口</param>
        /// <param name="message">要显示的消息</param>
        /// <param name="title">对话框标题</param>
        /// <param name="buttons">要显示的按钮类型，参见MessageBoxButtons类型</param>
        /// <param name="HomeKeyReturnValue">按home键后的默认返回值，参见HomeKeyReturnValue</param>
        /// <returns>返回结果，参见DialogResult类型</returns>
        public static DialogResult Show(IMzWindow parent, string message, string title, MessageBoxButtons buttons, HomeKeyReturnValue HomeKeyReturnValue)
        {
            IMzWindow dialogParent = Application.MainWindow;

            if(parent!=null)
            {
                dialogParent = parent;
            }

            return (DialogResult)CommonDlgMessageBoxEx(dialogParent == null ? IntPtr.Zero : dialogParent.HWnd, message, title, (int)buttons, (int)HomeKeyReturnValue);
        }
        #endregion

        /// <summary>
        /// 消息对话框按钮类型
        /// </summary>
        public enum MessageBoxButtons : int
        {
            /// <summary>
            /// 确定按钮
            /// </summary>
            MZ_OK = 0,
            /// <summary>
            /// 确定、取消按钮
            /// </summary>
            MZ_OKCANCEL = 1,
            /// <summary>
            /// 中止、重试、忽略按钮
            /// </summary>
            MZ_ABORTRETRYIGNORE = 2,
            /// <summary>
            /// 是、否、取消按钮
            /// </summary>
            MZ_YESNOCANCEL = 3,
            /// <summary>
            /// 是、否按钮
            /// </summary>
            MZ_YESNO = 4,
            /// <summary>
            /// 重试、取消按钮
            /// </summary>
            MZ_RETRYCANCEL = 5,
        }

        /// <summary>
        /// M键返回值
        /// </summary>
        public enum HomeKeyReturnValue : int
        {
            SHK_RET_DEFAULT = 0,

            /// CMzWnd::OnShellHomeKey()的返回值, SHK_RET_APPEXIT_SHELLTOP: 程序退出, SHELL置顶
            SHK_RET_APPEXIT_SHELLTOP = 1,

            /// CMzWnd::OnShellHomeKey()的返回值, SHK_RET_APPNOEXIT_SHELLNOTOP: 程序不退出, SHELL不置顶
            SHK_RET_APPNOEXIT_SHELLNOTOP = 2,

            /// CMzWnd::OnShellHomeKey()的返回值, SHK_RET_APPNOEXIT_SHELLTOP: 程序不退出, SHELL置顶
            SHK_RET_APPNOEXIT_SHELLTOP = 3,
        }
        /// <summary>
        /// 对话框返回值
        /// </summary>
        public enum DialogResult : int
        {
            /// <summary>
            /// Yes=是
            /// </summary>
            YES = 1,
            /// <summary>
            /// 确定
            /// </summary>
            OK = 1,
            /// <summary>
            /// 重试
            /// </summary>
            RETRY = 1,
            /// <summary>
            /// No=否
            /// </summary>
            NO = 2,
            /// <summary>
            /// 取消
            /// </summary>
            CANCEL = 2,
            /// <summary>
            /// 中止
            /// </summary>
            ABORT = 2,
            /// <summary>
            /// 忽略
            /// </summary>
            IGNORE = 3,
        }
    }
}
